layui.use(['HttpRequest', 'table', 'func', 'layer'], function () {
    var HttpRequest = layui.HttpRequest;
    var table = layui.table;
    var func = layui.func;
    var layer = layui.layer;

    /**
     * 系统管理--菜单管理
     */
    var DelApply = {
        tableId: "DelApplyTable",
        condition: {
            studentName: "",
            studentCode: "",
        },

        // treeTable实例
        treeTableInstance: null
    };

    /**
     * 初始化表格的列
     */
    DelApply.initColumn = function () {
        return [[
            {type: 'numbers'},
            {field: 'schoolName',align: "left", sort: true, title: '幼儿园', minWidth: 120},
            {field: 'teacherName', align: "left", sort: true, title: '申请人', minWidth: 120},
            {field: 'studentName', align: "left", sort: true, title: '学生姓名', minWidth: 120},
            {field: 'studentCode', align: "left", sort: true, title: '学生身份证', minWidth: 120},
            {field: 'approvalType', align: "left", sort: true, title: '审批类型', minWidth: 120,
                templet: function (data) {
                    var type="<span class='layui-badge layui-bg-green'>申请</span>";
                    if(data.approvalType && data.approvalType=="reject"){
                        type="<span class='layui-badge'>拒绝</span>";
                    }
                    else if(data.approvalType && data.approvalType=="agree"){
                        type="<span class='layui-badge layui-bg-yellow'>同意</span>";
                    }
                    return type;
                }
            },
            {field: 'applyTime', align: "center", sort: true, title: '申请时间', minWidth: 120            },
            {field: 'approvalTime', align: "center", sort: true, title: '审批时间', minWidth: 120},
            {field: 'applyReason', align: "left",  title: '删除原因', minWidth: 120},
            {field: 'rejectReason', align: "left", title: '拒绝原因', minWidth: 145}
        ]];
    };


    var tableResult = table.render({
        elem: '#' + DelApply.tableId,
        url: Feng.ctxPath + '/delapply/page',
        page: true,
        request: {pageName: 'pageNo', limitName: 'pageSize'}, //自定义分页参数
        height: "full-158",
        cellMinWidth: 100,
        cols: DelApply.initColumn(),
        parseData: Feng.parseData,
        where:{"isApproval":'1'}
        ,autoSort: false
    });

    table.on('sort(DelApplyTable)', function (obj) {
        table.reload(DelApply.tableId, {
            initSort: obj //记录初始排序
            , where: {
                sortBy: obj.field //排序字段
                , orderBy: obj.type //排序方式
            }
        });
    });


    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        DelApply.search();
    });
    /**
     * 点击查询按钮
     */
    DelApply.search = function () {
        var queryData = {};
        queryData['studentName'] = $("#studentName").val();
        queryData['studentCode'] = $("#studentCode").val();
        queryData['schoolName'] = $("#schoolName").val();
        table.reload(DelApply.tableId, {
            where: queryData,
            page: {curr: 1}
        });
    };

    table.on('tool(DelApplyTable)', function (obj) {
        var event = obj.event;
        var data = obj.data;
        if (event === 'agree') {
            DelApply.openEditDlg(data);
        }
    });

});
